<template>
  <div class="section create-sections">
    <div v-if="title && title.length > 0" class="section-header">
      <div :style="{ 'border-left-color': mColor }" class="section-mark"/>
      <div class="section-title">{{ title }}</div>
      <el-dropdown v-if="dropdownItems && dropdownItems.length > 0"
                   class="create-sections__more"
                   trigger="click"
                   @command="handleTypeClick">
        <i style="cursor: pointer;" class="el-icon-more"/>
        <template v-slot:dropdown>
          <el-dropdown-menu>
            <el-dropdown-item v-for="(item, index) in dropdownItems" :key="index"
                              :icon="item.icon"
                              :command="item.command">{{ item.label }}
            </el-dropdown-item>
          </el-dropdown-menu>
        </template>
      </el-dropdown>
      <slot name="header"/>
    </div>
    <div class="content create-sections-content">
      <slot/>
    </div>
  </div>
</template>

<script setup>

defineOptions({
  name: 'CreateSections',
})

const props = defineProps({
  title: {
    type: String,
    default: ''
  },
  mColor: {
    type: String,
    default: '#2362FB'
  },
  dropdownItems: Array
})

const emits = defineEmits(['command-select'])

const handleTypeClick = (type) => {
  emits('command-select', type)
}
</script>

<style lang="scss" scoped>
.section {
  position: relative;
  background-color: white;
  margin-top: 8px;
}

.section:first-child {
  margin-top: 0;
}

.section-mark {
  border-left-width: 4px;
  border-left-style: solid;
  border-radius: 2px;
  height: 14px;
}

.section-header {
  display: flex;
  align-items: center;
  padding: 5px 15px;
}

.section-title {
  font-size: 14px;
  color: #333;
  font-weight: 600;
  margin-left: 8px;
  flex-shrink: 0;
}

.create-sections__more {
  position: absolute;
  right: 15px;
}

.content {
  padding: 0 10px;
}
</style>
